package com.sgb.member.ui.adapter;

import android.content.Context;
import android.view.View;


import com.sgb.member.BR;
import com.sgb.member.R;
import com.sgb.member.databinding.ItemChooseMemberTypeBinding;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.view.selection.CommonPopEntity;

import java.util.List;

public class ChooseMemberTypeAdapter extends BaseRecycleAdapter<CommonPopEntity> {

    private boolean isDelete;

    public ChooseMemberTypeAdapter(Context context, List<CommonPopEntity> datas) {
        super(context, R.layout.item_choose_member_type, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final CommonPopEntity entity) {
        holder.setBinding(BR.viewModel, entity);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        ((ItemChooseMemberTypeBinding) holder.getmBinding()).rlDelete.setVisibility(isDelete ? View.VISIBLE : View.GONE);
        ((ItemChooseMemberTypeBinding) holder.getmBinding()).rlDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isDelete()) {
                    getDatas().remove(position);
                    notifyDataSetChanged();
                }
            }
        });
    }

    public boolean isDelete() {
        return isDelete;
    }

    public void setDelete(boolean delete) {
        isDelete = delete;
        notifyDataSetChanged();
    }
}
